#ifndef __AP_PERIPHERAL_HANDLING_H__
#define __AP_PERIPHERAL_HANDLING_H__

// Send key events faster than human finger can do
#define CRAZY_KEY_TEST		0

//0:Don't show power off log when screen saver enable
#define SCRN_ON_PW_OFF_LOG	1

typedef void (*KEYFUNC) (INT16U * tick_cnt_ptr);

typedef struct
{
	KEYFUNC key_function;
	KEYFUNC fast_key_fun;
	INT16S	key_val_L;
	INT16S	key_val_H;
	INT16U	key_cnt;
} KEYSTATUS;

enum
{
	USBD_CONNECTED_EMPTY = 0,
	USBD_CONNECTED_TO_CHARGER,
	USBD_CONNECTED_TO_HOST,
	USBD_CONNECTED_AND_HOST_JUST_REMOVED
};

#if C_TOUCH_PANEL
typedef struct
{
	INT32U startX;
	INT32U endX;
	INT32U startY;
	INT32U endY;
}ITEM_LOCATION;

typedef struct
{
	INT32U itemCount;
	ITEM_LOCATION* pitemLocatinArray;
	MSG_Q_ID msgQID;
	INT32U msgDownEvent;
	INT32U msgUpEvent;
	INT32U msgSlide_DownEvent;
	INT32U msgSlide_UpEvent;


}TOUCH_KEY_EVENT;
#endif // #if C_TOUCH_PANEL

extern INT8U	s_usbd_pin;
extern INT8U	usbd_exit;

extern void		ap_peripheral_init(void);
extern void		ap_peripheral_key_judge(void);
extern void		ap_peripheral_usbd_io_detection(void);
extern INT8U	ap_peripheral_get_usbd_io_status(void);
extern INT8U	ap_peripheral_get_usbd_connection_state(void);
extern void		ap_peripheral_set_usbd_connection_state(INT8U state);
extern void		ap_peripheral_key_register(INT8U type);
extern void		ap_peripheral_gsensor_data_register(void);
extern void		ap_peripheral_motion_detect_judge(void);
extern void		ap_peripheral_motion_detect_start(void);
extern void		ap_peripheral_motion_detect_stop(void);

extern void		ap_peripheral_auto_off_force_disable_set(INT8U auto_off_disable);
extern void		ap_peripheral_lcd_backlight_set(INT8U type);
extern INT32U 	ap_peripheral_lcd_backlight_get(void);

extern void		ap_peripheral_night_mode_set(INT8U type);

extern void		ap_TFT_backlight_tmr_check(void);
extern void		ap_peripheral_read_gsensor(void);

extern void		ap_peripheral_ad_key_judge(void);
extern void		ap_peripheral_config_store(void);

extern void		ap_peripheral_clr_screen_saver_timer(void);

extern INT8U	back_a_car_status_get(void);
extern INT32S	ap_peripheral_back_detect(void);
extern INT8U	back_a_car_status_get(void);
extern void		back_a_car_status_set(INT8U val);
extern INT32S   ap_peripheral_rtc_alarm_set_time(INT32U sec);

extern INT32U	ap_peripheral_get_host_io_status(void);

#if C_TOUCH_PANEL
#include "drv_l2_touch_panel.h"
extern void ap_peripheral_touch_key_register(void* param);
extern void ap_peripheral_touch_panel_key_process(TOUCH_PANEL_KEY_INFO_S *key_info);
extern void Touch_Key_Register_Lock(void);
extern void Touch_Key_Register_Unlock(void);
#endif

#if C_BATTERY_DETECT
extern void		ap_peripheral_battery_check_calculate(INT16U battery_value);
#endif

#if CRAZY_KEY_TEST
extern INT32U	crazy_key_enable;
extern void		ap_peripheral_crazy_key_test(void);
extern void		ap_peripheral_touch_panel_crazykey_test(void);
#endif

#if C_RTC_REBOOT
extern INT32S	ap_peripheral_rtc_alarm_set(void);
extern void		ap_peripheral_rtc_reboot_init(void);

#endif

#endif // __AP_PERIPHERAL_HANDLING_H__
